package com.huanwang.commonlibrary.base

import android.os.Bundle
import android.util.DisplayMetrics
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.huanwang.commonlibrary.utils.activity.AppManager
import com.tqzhang.stateview.core.LoadManager

abstract class BaseActivity : AppCompatActivity(){

    abstract fun onLayoutID():Int
    abstract fun onLoadDate(viewDataBinding: ViewDataBinding)
    var loadManager : LoadManager?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
     var dataBinding =   DataBindingUtil.setContentView<ViewDataBinding>(this, onLayoutID())
        loadManager = LoadManager.Builder()
            .setViewParams(this)
            .build()
        loadManager?.showSuccess()
        onLoadDate(dataBinding)
        initFontScale()
        //添加创建的Activity
        AppManager.appManager.addActivity(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        //删除添加的Activity
        AppManager.appManager.removeActivity(this)
    }




    //老人机  可以再 手机的设置里面设置字体大小，防止布局变形，让他对App不起作用
    private  fun initFontScale() {
        val configuration = resources.configuration
        configuration.fontScale = 1.toFloat()
        //0.85 小, 1 标准大小, 1.15 大，1.3 超大 ，1.45 特大
        val metrics = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(metrics)
        metrics.scaledDensity = configuration.fontScale * metrics.density
        baseContext.resources.updateConfiguration(configuration, metrics)
    }
}